import os
path = os.getcwd()

# 定义成绩分段
score_ranges = {"优秀": 0, "良好": 0, "中等": 0, "及格": 0, "不及格": 0}

# 读取文件内容
with open(path + "\\2025_07_01\\score.txt", "r", encoding="utf-8") as file:
    lines = file.readlines()

# 解析成绩并统计
total_students = len(lines)
for line in lines:
    name, score = line.strip().split()
    score = int(score)

    if score >= 90:
        score_ranges["优秀"] += 1
    elif score >= 80:
        score_ranges["良好"] += 1
    elif score >= 70:
        score_ranges["中等"] += 1
    elif score >= 60:
        score_ranges["及格"] += 1
    else:
        score_ranges["不及格"] += 1

# 计算占比
for key in score_ranges:
    score_ranges[key] = (
        score_ranges[key],
        round(score_ranges[key] / total_students * 100, 2),
    )

# 输出结果
print("成绩统计结果：")
for key, value in score_ranges.items():
    count, percentage = value
    print(f"{key}: {count}人, 占比{percentage}%")
